package CH5;

/**
 * Created by Cai Ye on 2016/3/29.
 */

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class TryCatchFinallyFileUtil {
    public static String readFile(String name) throws FileNotFoundException {
        StringBuilder text = new StringBuilder();
        Scanner console = null;
        try {
            console = new Scanner(new FileInputStream(name));
            while (console.hasNext()) {
                text.append(console.nextLine()).append('\n');
            }
        } finally {
            if (console != null) {
                console.close();
            }
        }
        return text.toString();
    }
}
